﻿

using System.Net;

namespace Xfs
{
	[XfsObjectSystem]
	public class XfsNetOuterComponentAwakeSystem : XfsAwakeSystem<XfsNetOuterComponent,XfsSenceType>
	{
		public override void Awake(XfsNetOuterComponent self, XfsSenceType a)
		{
			self.SenceType = a;
			if (XfsStartConfigComponent.Instance == null) return;
			if (XfsStartConfigComponent.Instance.StartConfig == null) return;
			if (XfsStartConfigComponent.Instance.StartConfig.Adress == null) return;
			if (XfsStartConfigComponent.Instance.StartConfig.Port == 0) return;

            if (self.MessageDispatcher == null)
            {
                self.MessageDispatcher = new XfsOuterMessageDispatcher();
            }

            self.ArgsInit(XfsStartConfigComponent.Instance.StartConfig.Adress, XfsStartConfigComponent.Instance.StartConfig.Port, XfsStartConfigComponent.Instance.StartConfig.MaxLiningCount);

		}       
    }
	[XfsObjectSystem]
	public class XfsNetOuterComponentAwake1System : XfsAwakeSystem<XfsNetOuterComponent, XfsSenceType>
	{
		public override void Awake(XfsNetOuterComponent self, XfsSenceType a)
		{
			self.SenceType = a;
			if (XfsStartConfigComponent.Instance == null) return;
			if (XfsStartConfigComponent.Instance.StartConfig == null) return;
			if (XfsStartConfigComponent.Instance.StartConfig.Adress == null) return;
			if (XfsStartConfigComponent.Instance.StartConfig.Port == 0) return;

            if (self.MessageDispatcher == null)
            {
                self.MessageDispatcher = new XfsOuterMessageDispatcher();
            }
            self.ArgsInit(XfsStartConfigComponent.Instance.StartConfig.Adress, XfsStartConfigComponent.Instance.StartConfig.Port, XfsStartConfigComponent.Instance.StartConfig.MaxLiningCount);

		}
	}


	[XfsObjectSystem]
	public class XfsNetOuterComponentLoadSystem : XfsLoadSystem<XfsNetOuterComponent>
	{
		public override void Load(XfsNetOuterComponent self)
		{
            if (self.MessageDispatcher == null)
            {
                self.MessageDispatcher = new XfsOuterMessageDispatcher();
            }
            self.ArgsInit();
		}
	}

	[XfsObjectSystem]
	public class XfsNetOuterComponentUpdateSystem : XfsUpdateSystem<XfsNetOuterComponent>
	{
		public override void Update(XfsNetOuterComponent self)
		{
			this.NetOuterStart(self);
		}

		private void NetOuterStart(XfsNetOuterComponent self)
		{
			if (!self.IsOuter) return;

			if (self.IsServer)
			{
				self.ServerListenStart();
			}
			else
			{
				self.ClientConnentStart();
			}
		}


	}
}